package com.cssw.fyzb.web.service;

import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.core.dao.team.TeamDao;
import com.cssw.fyzb.core.dao.team.UserTreeDao;
import com.cssw.fyzb.core.dao.user.UserDao;
import com.cssw.fyzb.core.model.dodb.Appeal;
import com.cssw.fyzb.core.model.dodb.Team;
import com.cssw.fyzb.core.model.dodb.User;
import com.cssw.fyzb.web.vo.AppealVo;
import com.cssw.fyzb.web.vo.TeamVo;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Auther: zzf
 * @Date: 2020/12/3 14:35
 * @Description:
 */
@Service
public class TeamService  {

    @Autowired
    private UserTreeDao userTreeDao;

    @Autowired
    private UserDao userDao;

    public AjaxPage list(int page, int limit, Map param) {
        Page<User> list= userDao.listUserDirectFriendByCond(param, page, limit);
        List<TeamVo> teamVos = new ArrayList<>();
        if (null != list.getList() && list.getList().size() != 0) {
            TeamVo teamVo = null;
            for (User func : list.getList()) {
                teamVo = new TeamVo();
                teamVo.setUserId(func.getUserId());
                teamVo.setMobile(func.getMobile());
                teamVo.setNickName(func.getNickName());
                teamVo.setTeamLevel(func.getTeamLevel());
                int count=userTreeDao.getTeamNum(func.getUserId());
                teamVo.setTeamCount(count);
                int childNum = userTreeDao.getTeamChildNum(func.getUserId());
                teamVo.setTeamChildCount(childNum);
                teamVos.add(teamVo);
            }
        }
        return AjaxPage.success(teamVos,list.getTotalRow(),list.getTotalPage());

    }

}
